const host = 'http://localhost/ccx_api/public/api/v1/' 
 
function request (url, method, data, header = {}) {
  /* wx.showLoading({
    title: '加载中' // 数据请求前loading
  }) */
  return new Promise((resolve, reject) => {
    wx.request({
      url: host + url, // 仅为示例，并非真实的接口地址
      method: method,
      data: data,
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        /* wx.hideLoading() */
        resolve(res)
      },
      fail: function (res) {
        wx.hideLoading()
        // reject(false)
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  })
}
 
function GET (obj) {
  return request(obj.url, 'GET', obj.data)
}
 
function POST (obj) {
  return request(obj.url, 'POST', obj.data)
}
 
export default {
  request,
  GET,
  POST,
  host
}
